/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import java.sql.Statement;
import java.util.List;
import Entity.Order;
import java.sql.ResultSet;
import java.util.ArrayList;

/**
 *
 * @author DUNGDA
 */
public class DAO_Order {

    public static boolean deleteOrder(int ID) {
        String sqldelete = "DELETE FROM tblOrders WHERE orderID =" + ID;
        
        try {
            Statement st = DAO_Connect.getConnection().createStatement();
            if(st.execute(sqldelete)){
                return true;            
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
    
    public void EditOrder(int id, String date, String shipAdd, String shipName, String shipPhone, int cusid, int status, float orderPrice){
        String sql = "UPDATE tblOrders SET orderID = '"+id+"', orderDate = '"+date+"',orderShipAddress = "+shipAdd+", orderReceivedName = "+shipName+", orderReceivedPhone = '"+shipPhone+"', cusID = '"+cusid+"', orderStaID = '"+status+"', orderTotalPrice = '"+orderPrice+"' WHERE (orderID ="+id+")";
        try{
        Statement st = DAO_Connect.getConnection().createStatement();
        ResultSet rs = st.executeQuery(sql);
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }
    
    public static List<Order> showOrder(){
        String query = "SELECT * FROM tblOrders INNER JOIN tblOrderStatus ON tblOrders.OrderId = tblOrderStatus.orderStaID";
        List<Order> lstOrd = new ArrayList<Order>();
        try {
            Statement st = DAO_Connect.getConnection().createStatement();
            ResultSet rs = st.executeQuery(query);
            while (rs.next()) {
                int id = rs.getInt(1);
                String date = rs.getString(2);
                String shipAdd = rs.getString(3);
                String shipName = rs.getString(4);
                String shipPhone = rs.getString(5);
                int cusid = rs.getInt(6);
                int status = rs.getInt(7);
                float orderPrice = rs.getFloat(8);
                int orderStaId = rs.getInt(9);
                String orderStaName = rs.getString(10);
                Order ord = new Order(id, date, shipAdd, shipName, shipPhone, cusid, status, orderPrice, orderStaId, orderStaName);
                lstOrd.add(ord);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return lstOrd;
    }
}
